package com.neusoft.yuejian26.yuejian_26.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.neusoft.yuejian26.yuejian_26.Activity.ProSimpActivity;
import com.neusoft.yuejian26.yuejian_26.Bean.Probean;
import com.neusoft.yuejian26.yuejian_26.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2017/10/20 0020.
 */

public class ProAdapter extends XRecyclerView.Adapter<XRecyclerView.ViewHolder> {
    private Context mContext;
    protected List mDataList;
    private LayoutInflater mlayoutInflater;
    public ProAdapter(Context mContext, List<Probean> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mlayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public XRecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mlayoutInflater.from(parent.getContext()).inflate(R.layout.prolist_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(XRecyclerView.ViewHolder holder, int position) {
        final Probean entity = (Probean) mDataList.get(position);
        if (null==entity)
            return;
        ProAdapter.ViewHolder viewHolder = (ProAdapter.ViewHolder) holder;
        viewHolder.pro_name.setText(entity.getMname());
        Picasso.with(mContext).load("http://115.159.93.244/new18yuejian/Public/upload/"+entity.getMpic()).into(viewHolder.pro_pic);
        viewHolder.proitem.setOnClickListener(new View.OnClickListener(){
            @Override
            public  void onClick(View v){
                Intent intent= new Intent(mContext, ProSimpActivity.class);
                Bundle bundle= new Bundle();
                bundle.putString("proiid",entity.getMid());
                bundle.putString("proname",entity.getMname());

                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    private class ViewHolder extends XRecyclerView.ViewHolder{
        TextView pro_name;
        CircleImageView pro_pic;
        CardView proitem;
        public ViewHolder(View v){
            super(v);
            pro_name= (TextView) v.findViewById(R.id.pro_name);
            pro_pic= (CircleImageView) v.findViewById(R.id.pro_pic);
            proitem= (CardView) v.findViewById(R.id.pro_item_card);
        }
    }
}
